package com.blog.config;
import com.blog.Utils.Result;
import com.blog.service.SearchService;
import com.blog.bean.vo.PageAndUserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author 任浩
 * @version 1.0
 */

@RestController
@RequestMapping("/search")
@Slf4j
public class SearchController {

    @Autowired
    private SearchService searchService;

    @GetMapping
    public Result search(@RequestParam("content") String content, @RequestParam("page") Integer page
                                , @RequestParam("pageNum") Integer pageNum, HttpSession session) throws IOException {
        //获得当前用户的id
        log.info("hello");
        Integer userId = (Integer) session.getAttribute("userId");
        PageAndUserVO pageAndUserVO= searchService.search(content,page,pageNum,userId);
        System.out.println("搜索出来的信息为：" + pageAndUserVO);
        return Result.success(pageAndUserVO);
    }
}
